package com.tzy.user;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 1. 数据结构：
 * 患者挂号就诊信息（在代码中，已定义VisitVo类对应下面的数据结构，并且模拟了数据）
 * visitId	患者就诊信息主键，为UUID
 * patientName	患者姓名
 * visitDatetime	看诊时间
 * doctorId	看诊医生ID
 * doctorName	看诊医生姓名
 * <p>
 * 2. 编码要求
 * 医院需要按看诊医生和看诊时间统计每个医生每天的看诊工作量，请处理模拟数据中所有的看诊记录，按以下格式输出，建议直接利用ConsultCountVo
 * <p>
 * 李医生	2017-09-17	10人
 * 王医生	2017-09-17	8人
 * 赵医生	2017-09-17	6人
 * 张医生	2017-09-18	4人
 * 黄医生	2017-09-18	3人
 * 胡医生	2017-09-18	5人
 * 钱医生	2017-09-18	4人
 * 孙医生	2017-09-18	3人
 * <p>
 * 3. 数据要求（重要考点）
 * !!!看诊时间以yyyy-MM-dd格式显示
 * !!!按照看诊日期和医生ID升序排序（日期小的在前，日期相同时，医生ID小的在前）
 **/
public class ListSorting {


    public static void main(String[] args) {
        //listConsultCount();
        showInfo();
    }

    private static void showInfo() {
        List<VisitVo> list = prepareData();
        Collections.sort(list, (v1, v2) -> {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            try {
                Date dt1 = format.parse(v1.getVisitDatetime());
                Date dt2 = format.parse(v2.getVisitDatetime());
                if (dt1.getTime() > dt2.getTime()) {
                    return 1;
                }else if (dt1.getTime() < dt2.getTime()) {
                    return -1;
                } else {
                    return 0;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return 0;
        });
        list.forEach(visitVo -> System.out.println(visitVo.getDoctorName()+" "+visitVo.getVisitDatetime()));

    }

    private static List<ConsultCountVo> listConsultCount() {
        List<VisitVo> visitList = prepareData();
        // TODO 请实现统计看诊工作量逻辑

        System.out.println(visitList.size());
        return null;
    }

    private static List<VisitVo> prepareData() {
        List<VisitVo> visitList = new ArrayList<VisitVo>();
        visitList.add(new VisitVo("2017-09-18 08:30:00", "1001", "张医生"));
        visitList.add(new VisitVo("2017-09-18 08:50:00", "1001", "张医生"));
        visitList.add(new VisitVo("2017-09-18 09:12:00", "1001", "张医生"));
        visitList.add(new VisitVo("2017-09-18 09:20:00", "1001", "张医生"));
        visitList.add(new VisitVo("2017-09-18 08:40:00", "1002", "黄医生"));
        visitList.add(new VisitVo("2017-09-18 09:10:00", "1002", "黄医生"));
        visitList.add(new VisitVo("2017-09-18 09:30:00", "1002", "黄医生"));
        visitList.add(new VisitVo("2017-09-18 08:30:00", "1003", "李医生"));
        visitList.add(new VisitVo("2017-09-18 08:32:00", "1003", "李医生"));
        visitList.add(new VisitVo("2017-09-18 08:39:00", "1003", "李医生"));
        visitList.add(new VisitVo("2017-09-18 08:42:00", "1003", "李医生"));
        visitList.add(new VisitVo("2017-09-18 08:50:00", "1003", "李医生"));
        visitList.add(new VisitVo("2017-09-18 08:30:00", "2001", "王医生"));
        visitList.add(new VisitVo("2017-09-18 08:50:00", "2001", "王医生"));
        visitList.add(new VisitVo("2017-09-18 09:12:00", "2001", "王医生"));
        visitList.add(new VisitVo("2017-09-18 09:20:00", "2001", "王医生"));
        visitList.add(new VisitVo("2017-09-18 08:40:00", "2002", "赵医生"));
        visitList.add(new VisitVo("2017-09-18 09:10:00", "2002", "赵医生"));
        visitList.add(new VisitVo("2017-09-18 09:30:00", "2002", "赵医生"));
        visitList.add(new VisitVo("2017-09-18 08:30:00", "2003", "胡医生"));
        visitList.add(new VisitVo("2017-09-18 08:32:00", "2003", "胡医生"));
        visitList.add(new VisitVo("2017-09-18 08:39:00", "2003", "胡医生"));
        visitList.add(new VisitVo("2017-09-18 08:42:00", "2003", "胡医生"));
        visitList.add(new VisitVo("2017-09-18 08:50:00", "2003", "胡医生"));
        visitList.add(new VisitVo("2017-09-18 08:30:00", "3001", "钱医生"));
        visitList.add(new VisitVo("2017-09-18 08:50:00", "3001", "钱医生"));
        visitList.add(new VisitVo("2017-09-18 09:12:00", "3001", "钱医生"));
        visitList.add(new VisitVo("2017-09-18 09:20:00", "3001", "钱医生"));
        visitList.add(new VisitVo("2017-09-18 08:40:00", "3002", "孙医生"));
        visitList.add(new VisitVo("2017-09-18 09:10:00", "3002", "孙医生"));
        visitList.add(new VisitVo("2017-09-18 09:30:00", "3002", "孙医生"));
        visitList.add(new VisitVo("2017-09-17 08:30:00", "1003", "李医生"));
        visitList.add(new VisitVo("2017-09-17 08:32:00", "1003", "李医生"));
        visitList.add(new VisitVo("2017-09-17 08:39:00", "1003", "李医生"));
        visitList.add(new VisitVo("2017-09-17 08:42:00", "1003", "李医生"));
        visitList.add(new VisitVo("2017-09-17 08:50:00", "1003", "李医生"));
        visitList.add(new VisitVo("2017-09-17 08:30:00", "2001", "王医生"));
        visitList.add(new VisitVo("2017-09-17 08:50:00", "2001", "王医生"));
        visitList.add(new VisitVo("2017-09-17 09:12:00", "2001", "王医生"));
        visitList.add(new VisitVo("2017-09-17 09:20:00", "2001", "王医生"));
        visitList.add(new VisitVo("2017-09-17 08:40:00", "2002", "赵医生"));
        visitList.add(new VisitVo("2017-09-17 09:10:00", "2002", "赵医生"));
        visitList.add(new VisitVo("2017-09-17 09:30:00", "2002", "赵医生"));

        return visitList;
    }
}

class ConsultCountVo {
    private String doctorId;
    private String doctorName;
    private String visitDate;
    private int consultCount;

    public ConsultCountVo() {

    }

    public String getDoctorId() {
        return doctorId;
    }

    public void setDoctorId(String doctorId) {
        this.doctorId = doctorId;
    }

    public String getDoctorName() {
        return doctorName;
    }

    public void setDoctorName(String doctorName) {
        this.doctorName = doctorName;
    }

    public String getVisitDate() {
        return visitDate;
    }

    public void setVisitDate(String visitDate) {
        this.visitDate = visitDate;
    }

    public int getConsultCount() {
        return consultCount;
    }

    public void setConsultCount(int consultCount) {
        this.consultCount = consultCount;
    }

}

class VisitVo {
    private UUID visitId;
    private String patientName;
    private String visitDatetime;
    private String doctorId;
    private String doctorName;

    public VisitVo() {

    }

    public VisitVo(String visitDatetime, String doctorId, String doctorName) {
        this.visitId = UUID.randomUUID();
        this.patientName = "患者" + this.visitId.toString().substring(0, 4);
        this.visitDatetime = visitDatetime;
        this.doctorId = doctorId;
        this.doctorName = doctorName;
    }

    public UUID getVisitId() {
        return visitId;
    }

    public void setVisitId(UUID visitId) {
        this.visitId = visitId;
    }

    public String getPatientName() {
        return patientName;
    }

    public void setPatientName(String patientName) {
        this.patientName = patientName;
    }

    public String getVisitDatetime() {
        return visitDatetime;
    }

    public void setVisitDatetime(String visitDatetime) {
        this.visitDatetime = visitDatetime;
    }

    public String getDoctorId() {
        return doctorId;
    }

    public void setDoctorId(String doctorId) {
        this.doctorId = doctorId;
    }

    public String getDoctorName() {
        return doctorName;
    }

    public void setDoctorName(String doctorName) {
        this.doctorName = doctorName;
    }

}
